<template>
  <div>
    <div class="login">
      <div class="content">
        <div class="left">
          <img
            class="img"
            src="https://fanglingdi.oss-cn-beijing.aliyuncs.com/other/9c8f7caef8d25c24e3e7e231b19d9fe2eabaa852.png"
            alt=""
          />
        </div>

        <div class="login-con">
          <div class="login-con-body">
            <div class="login-logo">
              <img
                src="https://fanglingdi.oss-cn-beijing.aliyuncs.com/other/84a9c07ced6dd2734ddc0e129d46af39d3ebdd3e.png"
                alt=""
              />
            </div>
            <div class="form">
              <el-form
                ref="ruleForm"
                :model="setdata"
              >
                <el-form-item class="inputColor" prop="admin" label-width="auto">
                  <el-input
                    v-model="setdata.admin"
                    placeholder="请输入用户名"
                    prefix-icon="el-icon-user"
                  ></el-input>
                </el-form-item>
                <el-form-item class="inputColor" prop="password" label-width="auto">
                  <el-input
                    v-model="setdata.password"
                    placeholder="请输入密码"
                    type="password"
                    prefix-icon="el-icon-lock"
                  ></el-input>
                </el-form-item>
                <el-form-item prop="resource" label-width="auto">
                  <el-checkbox
                    v-model="setdata.resource"
                    false-label="0"
                    true-label="1"
                    size="small"
                    class="checkout"
                  >
                    <el-link
                      href="https://element.eleme.io"
                      target="_blank"
                      class="link"
                      type="info"
                    >
                      同意并遵守《房领地平台规则》
                    </el-link>
                  </el-checkbox>
                </el-form-item>
                <el-form-item>
                  <el-button class="btnLogin" type="primary" @click="login">登录</el-button>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue';
import { useStore } from 'vuex';
import { login as loginApi } from '../api/user';
import type { LoginQuery } from '../interface/sys';
import storage from '../utils/storage';

let store = useStore();

let setdata:LoginQuery = reactive(
  {
    admin: '',
    password: '',
    resource: 1,
  },
);
let login = async () => {
  const result = await loginApi(setdata);
  console.log(result.data.adminId);
  storage.setItem('token', result.data.token);
  store.commit('user/setUserInfo', { adminId: result.data.adminId, truename: result.data.truename });
  store.commit('user/saveMenu', result.data.menu);
};
</script>

<style lang="scss" scoped>
:deep(.link){
  display: flex;
  flex-direction: row;
  align-items: center;
}
:deep(.el-checkbox__label){
  color: rgb(194, 198, 203);
  font-size: 12px!important;
}
.btnLogin{
  width: 100%;
  padding: 16px 0px;
  font-size: 16px;
  background: #007aff;
}

:deep(.el-input__inner) {
  background: #f4f8ff !important;
  border: none;
}
:deep(.el-input__icon) {
  font-size: 22px;
}
.login .content .login-con .login-con-body .login-logo img {
  width: 242px;
  height: 41px;
  display: block;
  margin: 0 auto 25px;
}
.login .content .login-con .login-con-body {
  width: 320px;
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
}
.login .content .login-con {
  width: 50%;
  position: relative;
}
.login {
  width: 100%;
  min-height: calc(100vh - 50px);
  background-color: #f1fcfe;
  padding: 25px 45px;
}
.login .content {
  background: #fff;
  box-shadow: 0 3px 6px #e3e2e2;
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  min-height: calc(100vh - 50px);
}
.login .content .left {
  background: #2579ff;
  width: 50%;
  position: relative;
}
.login .content .left .img {
  width: 500px;
  height: 364px;
  display: block;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
</style>
